package com.hctforgreen.greenservice.machineManager.impl;

import android.app.Activity;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;

import com.hctforgreen.greenservice.R;
import com.hctforgreen.greenservice.machineManager.MachineBase;
import com.hctforgreen.greenservice.model.LocationEntity;
import com.hctforgreen.greenservice.model.PwdEntity;
import com.hctforgreen.greenservice.model.SYHotWaterMachineEntity;
import com.hctforgreen.greenservice.ui.adapter.SpinnerStringsAdapter;
import com.hctforgreen.greenservice.utils.HctResult;
import com.hctforgreen.greenservice.utils.Utils;
/**
 * 商用热水机-热水工程
 * @author 390694
 *
 */
public class ComHotWater extends MachineBase{

	private View layout_HotWater;
	
	private Spinner spinner_tank_size;
	private Spinner spinner_installation_position;
	private Spinner spinner_unit_and_the_water_tank_drop;
	private Spinner spinner_backwater_position;
	private Spinner spinner_use_of_water;
	
	
	/**
	 * // 多联机：内机与内机的最大落差；热水机：使用水源;商用热水机：使用水源
	 */
	private String inDropHeight;
	/**
	 * 商用热水机：是否安装回水装置// 多联机：外机最大风管长度；热水机：使用人数
	 */
	private String tubeLength;
	/**
	 * // 多联机：内机与外机的最大落差；热水机：冷媒连接管||商用热水机：机组与水箱落差
	 */
	private String dropHeight;
	/**
	 * // 热水机： 配套水箱 || 商用热水机：水箱大小
	 */
	private String matchWaterbox;
	/**
	 * // 多联机：内机到外机连接管长度；热水机：水箱安装位置 ||商用热水机：机组安装位置
	 */
	private String ioConnectionLength;
	
	/**
	 * 商用热水机 使用场所
	 */
	private String operationSite;

	//商用热水机 热水工程特有属性实体类，关联提示页面用
	public SYHotWaterMachineEntity syHotWaterMachineEntity ;


	public void setOperationSite(String operationSite) {
		this.operationSite = operationSite;
	}

	public ComHotWater(Activity context) {
		super(context);
		initView();
		syHotWaterMachineEntity = new SYHotWaterMachineEntity();
	}

	@Override
	public void initView() {
		layout_HotWater = findViewById(R.id.layout_HotWater);
		
		spinner_tank_size = (Spinner) findViewById(R.id.spinner_tank_size);
		spinner_installation_position = (Spinner) findViewById(R.id.spinner_installation_position);
		spinner_unit_and_the_water_tank_drop = (Spinner) findViewById(R.id.spinner_unit_and_the_water_tank_drop);
		spinner_backwater_position = (Spinner) findViewById(R.id.spinner_backwater_position);
		spinner_use_of_water = (Spinner) findViewById(R.id.spinner_use_of_water_sy);
	}
	@Override
	public void showView() {
		layout_HotWater.setVisibility(View.VISIBLE);
		initTankSize();
		initUnit_installation_position();
		initUnit_and_the_water_tank_drop();
		initWhether_to_install();
		initHWUse_of_water();
	}
	@Override
	public void hideView() {
		layout_HotWater.setVisibility(View.GONE);
	}
	
	@Override
	public boolean validateView() {
		if (inDropHeight == null || tubeLength == null || dropHeight == null
				|| matchWaterbox == null || ioConnectionLength == null
				 ) {
			Utils.showToastCenter(activity,
					getString(R.string.barcode_info_is_incomplete));
			return false;
		}
		return true;
	}


	@Override
	public HctResult getPwdResult(PwdEntity paramEntity,LocationEntity locationEntity, boolean isClounServer) throws Exception {
		HctResult result = new HctResult();
		result = controller.getBootPwd(paramEntity.phone, paramEntity.stripeCode,
				locationEntity.getmGpsLocation() ,
				locationEntity.getmBaseLocation(), locationEntity.getmWifiLocation(),locationEntity.getProvince_loc(),
				locationEntity.getCity_loc(), locationEntity.getProvince(), locationEntity.getCity(), locationEntity.getDistrict(), paramEntity.street,
				paramEntity.projectName, paramEntity.ownerName, paramEntity.ownerPhone, paramEntity.remark,
				paramEntity.industry, ioConnectionLength,
				inDropHeight, dropHeight, tubeLength,
				"", "", matchWaterbox,
				"", "", "",
				locationEntity.getmLatitude() + "",locationEntity.getmLongitude() + "", operationSite, isClounServer);
		return result;
	}
    //关联提示页面用
	public HctResult getPwdResult(PwdEntity paramEntity,LocationEntity locationEntity, boolean isClounServer,SYHotWaterMachineEntity syHotWaterMachineEntity) throws Exception {
		HctResult result = new HctResult();
		result = controller.getBootPwd(paramEntity.phone, paramEntity.stripeCode,
				locationEntity.getmGpsLocation() ,
				locationEntity.getmBaseLocation(), locationEntity.getmWifiLocation(),locationEntity.getProvince_loc(),
				locationEntity.getCity_loc(), locationEntity.getProvince(), locationEntity.getCity(), locationEntity.getDistrict(), paramEntity.street,
				paramEntity.projectName, paramEntity.ownerName, paramEntity.ownerPhone, paramEntity.remark,
				paramEntity.industry, syHotWaterMachineEntity.getIoConnectionLength(),
				syHotWaterMachineEntity.getInDropHeight(), syHotWaterMachineEntity.getDropHeight(), syHotWaterMachineEntity.getTubeLength(),
				"", "", syHotWaterMachineEntity.getMatchWaterbox(),
				"", "", "",
				locationEntity.getmLatitude() + "",locationEntity.getmLongitude() + "", syHotWaterMachineEntity.getOperationSite(), isClounServer);
		return result;
	}

	
	/**
	 * 热水工程 水箱大小
	 */
	private void initTankSize() {
		final String[] items = getResources().getStringArray(R.array.tank_size);
		matchWaterbox = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_tank_size.setAdapter(adapter);

		spinner_tank_size.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					matchWaterbox = null;
				} else {
					matchWaterbox = items[arg2];
				}
				syHotWaterMachineEntity.setMatchWaterbox(matchWaterbox);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});
	}
	/**
	 * 商用热水机-热水工程：机组安装位置
	 */
	private void initUnit_installation_position() {
		
		final String[] items = getResources().getStringArray(
				R.array.unit_installation_position);
		ioConnectionLength = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_installation_position.setAdapter(adapter);

		spinner_installation_position.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					ioConnectionLength = null;
				} else {
					ioConnectionLength = items[arg2];
				}
				syHotWaterMachineEntity.setIoConnectionLength(ioConnectionLength);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}
	/**
	 * 商用热水机-热水工程：机组与水箱落差
	 */
	private void initUnit_and_the_water_tank_drop() {

		final String[] items = getResources().getStringArray(
				R.array.unit_and_the_water_tank_drop);
		dropHeight = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_unit_and_the_water_tank_drop.setAdapter(adapter);

		spinner_unit_and_the_water_tank_drop.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					dropHeight = null;
				} else {
					dropHeight = items[arg2];
				}
				syHotWaterMachineEntity.setDropHeight(dropHeight);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}
	/**
	 * 商用热水机-热水工程：是否安装回水装置
	 */
	private void initWhether_to_install() {

		final String[] items = getResources().getStringArray(
				R.array.whether_to_install_a_backwater_position);
		tubeLength = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_backwater_position.setAdapter(adapter);

		spinner_backwater_position.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					tubeLength = null;
				} else {
					tubeLength = items[arg2];
				}
				syHotWaterMachineEntity.setTubeLength(tubeLength);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}
	/**
	 * 商用热水机-热水工程：使用水源
	 */
	private void initHWUse_of_water() {

		final String[] items = getResources().getStringArray(
				R.array.use_of_water);
		inDropHeight = null;
		SpinnerStringsAdapter adapter = new SpinnerStringsAdapter(activity, items);
		spinner_use_of_water.setAdapter(adapter);

		spinner_use_of_water.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 0) {
					inDropHeight = null;
				} else {
					inDropHeight = items[arg2];
				}
				syHotWaterMachineEntity.setInDropHeight(inDropHeight);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

	}
}
